﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LibraryO2S;
using System.Data;
public partial class Administrator_ModuleEdit : System.Web.UI.Page
{


    BizModule report = new BizModule();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }

    }

    private void LoadData()
    {
        txtModuleName.Text = tblModule.Rows[0]["MODULENAME"].ToString();
        txtDescription.Text = tblModule.Rows[0]["DESCRIPTION"].ToString();
        txtSortDisplay.Text = tblModule.Rows[0]["SORTDISPLAY"].ToString();
        int status = int.Parse(tblModule.Rows[0]["STATUS"].ToString());
        if (status == 1)
        {
            cbStatus.Checked = true;
        }
        else
        {
            cbStatus.Checked = false;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int status = 0;
        if (cbStatus.Checked)
        {
            status = 1;
        }
        else
            status = 0;
        try
        {
            string modified = Session["USERNAME"].ToString();
            report.Update(MODULEID, txtModuleName.Text, txtDescription.Text, int.Parse(txtSortDisplay.Text), modified, status);
            divMessage.InnerHtml = O2S_Message.Success("Hệ thống", "Thực hiện thành công");

        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Hệ thống", "Phát hiện lỗi" + ex.Message);
        }

    }
    public int MODULEID
    {
        get
        {
            return int.Parse(Request.QueryString["MODULEID"].ToString());
        }
    }
    public DataTable tblModule
    {
        get
        {
            return report.ModuleByID(MODULEID);
        }
    }


}